package com.fjrcloud.controller;

import com.fjrcloud.entity.BasePrice;
import com.fjrcloud.entity.PriceType;
import com.fjrcloud.entity.ResponseBean;
import com.fjrcloud.entity.ResponseFactory;
import com.fjrcloud.service.BasePriceService;
import com.fjrcloud.utils.StatusUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Created by shengjian.lin on 17-2-11.
 */
@Controller
@RequestMapping("api/price")
public class BasePriceController {

    @Autowired
    private BasePriceService service;

    @RequestMapping("save")
    @ResponseBody
    public ResponseBean save(BasePrice price){
        return ResponseFactory.getResponseBean(StatusUtils.Success,service.save(price));
    }
    @RequestMapping("get")
    @ResponseBody
    public ResponseBean get(Integer id, PriceType type){
        if (id == null){
            return ResponseFactory.getResponseBean(StatusUtils.Success,service.get(type));
        }else{
            return ResponseFactory.getResponseBean(StatusUtils.Success,service.get(id));
        }
    }
    @RequestMapping("list")
    @ResponseBody
    public ResponseBean list(){
        return ResponseFactory.getResponseBean(StatusUtils.Success,service.list());
    }
    @RequestMapping("del")
    @ResponseBody
    public ResponseBean del(Integer id){
        service.del(id);
        return ResponseFactory.getResponseBean(StatusUtils.Success);
    }
}
